<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var len = +prompt("请输入数组的长度");
        if (isNaN(len) || len < 0) {
            console.log("输入有误");
        } else {
            //输入正确
            var arr = [];
            for (var i = 0; i < len; i++) {
                // 提示用户输入数组的这一项的值
                arr[i] = prompt("请输入数组第" + (i + 1) + "项的值");
            }
            console.log(arr);
        }
    </script>
</body>

</html>
